package com.aos.iot.protocol.hll.parser.data;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.lang.Dict;
import com.aos.iot.protocol.hll.constant.HllCmd;
import com.aos.iot.protocol.hll.constant.HllProp;
import org.springframework.stereotype.Component;

import java.util.List;


@Component("PushBindPipeDataParser")
public class PushBindPipeDataParser extends InteractiveBindPipeDataParser {

    private final List<String> encodeItems = CollUtil.newArrayList(
            HllProp.PILE_NO.getValue(),
            HllProp.PILE_CHANNEL_NO.getValue(),
            HllProp.PILE_OUTPUT_COIL_BIND_TABLE.getValue(),
            HllProp.PILE_SOFT_VERSION.getValue()
    );

    @Override
    public Dict encode(String payload) {
        return Dict.create()
            .set(HllProp.PILE_NO.getValue(), sub(payload, 0, 10, true, "0000000000"))
            .set(HllProp.PILE_CHANNEL_NO.getValue(), sub(payload, 10, 12, false, "00"))
            .set(HllProp.PILE_OUTPUT_COIL_BIND_TABLE.getValue(),
                    bindTableParser(sub(payload, 12, 204, false, defaultBindTable(16))))
            .set(HllProp.PILE_SOFT_VERSION.getValue(), sub(payload, 204, 206, false, "00"))
            ;
    }

    @Override
    public List<String> encodeItems() {
        return encodeItems;
    }

    @Override
    public String cmd() {
        return HllCmd.PUSH_BIND_POTENTIAL;
    }
}
